From: kfraser@localhost.localdomain Date: Mon, 31 Jul 2006 17:07:25 +0000 (+0100) Subject: [BLKTAP] Properly daemonise the blktap control daemon. Fixes bug #709. X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~15754^2~33 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=31c8886dc2adf4fb0bda8bb09b342080518e0fe4;p=xen.git [BLKTAP] Properly daemonise the blktap control daemon. Fixes bug #709. Signed-off-by: Harry Butterworth --- diff --git a/tools/blktap/drivers/blktapctrl.c b/tools/blktap/drivers/blktapctrl.c index f4ade5b780..14a86d9088 100644 --- a/tools/blktap/drivers/blktapctrl.c +++ b/tools/blktap/drivers/blktapctrl.c @@ -622,6 +622,38 @@ static void print_drivers(void) DPRINTF("Found driver: [%s]\n",dtypes[i]->name); } +/* Stevens. */ +static void daemonize(void) +{ + pid_t pid; + + /* Separate from our parent via fork, so init inherits us. */ + if ((pid = fork()) < 0) + DPRINTF("Failed to fork daemon\n"); + if (pid != 0) + exit(0); + + /* Session leader so ^C doesn't whack us. */ + setsid(); + + /* Let session leader exit so child cannot regain CTTY */ + if ((pid = fork()) < 0) + DPRINTF("Failed to fork daemon\n"); + if (pid != 0) + exit(0); + + /* Move off any mount points we might be in. */ + if (chdir("/") == -1) + DPRINTF("Failed to chdir\n"); + + /* Discard our parent's old-fashioned umask prejudices. */ + umask(0); + + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); +} + int main(int argc, char *argv[]) { char *devname; @@ -633,6 +665,7 @@ int main(int argc, char *argv[]) __init_blkif(); openlog("BLKTAPCTRL", LOG_CONS|LOG_ODELAY, LOG_DAEMON); + daemonize(); print_drivers(); init_driver_list();